import { number } from "echarts";

export const labelBaseMonthMixins = {
  data() {
    return {
      monthMix: null,
    };
  },
  mounted() {},
  methods: {

    dateChange(clickmodel, v) {
      this.monthMix = v
      if (clickmodel.idObject === "xlycb" && clickmodel.sField === "yf") {
        this.jsondata.bodydata["销量预测表明细"].forEach((i) => {
          i.forEach((iv) => {
            if (!iv.copyTitle) {
              iv.copyTitle = iv.sTitle
            }
            iv.sTitle = this.replaceNWithMonth(iv.copyTitle,v);
          });
        });
      }
    },
    // 匹配N+1,N-1,N
    replaceNWithMonth(str, month) {
      const currentMonth = month;
      // 月份调整函数（处理跨年）
      const adjustMonth = (month) => {
        if (month < 1) return month + 12;
        if (month > 12) return month - 12;
        return month;
      };
      const formatMonth = (month) => {
        const m = adjustMonth(month);
        return `${m}`;
      };
      return str.replace(/N(加([0-9]+)|减([0-9]+))?/g, (match, p1, p2, p3) => {
        if (!p1) {
          return formatMonth(currentMonth);
        } else if (p2) {
          const value = parseInt(p2, 10);
          return formatMonth(currentMonth + value);
        } else if (p3) {
          const value = parseInt(p3, 10);
          return formatMonth(currentMonth - value);
        }
        return match;
      });
    },
  },
};
